﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Bootstrap5.Abstractions;

/// <summary>
/// A provider witch is to build the bootstrap triggers using 'data-bs-*' data attribute.
/// </summary>
public class BootstrapTriggerBuilder:IDisposable
{
	public Dictionary<string, object> Triggers { get; private set; } = new();
	
	/// <summary>
	/// Set a data-bs-* attribute with name and value.
	/// The attribute will not been added when <paramref name="value"/> is null.
	/// </summary>
	/// <param name="name">The trigger name.</param>
	/// <param name="value">The trigger value.</param>
	/// <returns></returns>
    public BootstrapTriggerBuilder SetData(string name,object value)
	{
		if(value is null)
        {
			return this;
        }
		Triggers[name] = value.ToString().ToLower();
        return this;
	}

	

	public override string ToString()
	{
		return Triggers.Select(m => $"data-bs-{m.Key}=\"{m.Value}\"").Aggregate((prev, next) => $"{prev} {next}");
	}

    public void Dispose()
    {
		Triggers?.Clear();

	}
}
